package com.sixmac.controller;

import com.sixmac.annotation.AuthUser;
import com.sixmac.common.base.BaseController;
import com.sixmac.core.annotation.Validator;
import com.sixmac.core.base.model.Format;
import com.sixmac.core.toolbox.ajax.AjaxResult;
import com.sixmac.module.Tenant;
import com.sixmac.platform.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by admin on 2018/9/4.
 */
@Controller
@ResponseBody
@RequestMapping("/login")
public class LoginController extends BaseController {
    @Autowired
    LoginService loginService;


    /**
     * @api {post} /login/sendCaptcha 0.0发送验证码
     * @apiName login.sendCaptcha
     * @apiGroup login
     * @apiParam {String} phone 手机号码
     */
    @Validator(name = {"phone"}, format = {Format.REG_PHONE})
    @RequestMapping("/sendCaptcha")
    public AjaxResult sendCaptcha(String phone) {
        return loginService.sendCaptcha(phone);
    }

    /**
     * @api {post} /login/login 0.1登录
     * @apiName login.login
     * @apiGroup login
     * @apiParam {String} code code
     * @apiParam {String} nickname 微信昵称
     * @apiSuccess {String} user.code 123需要去绑定手机号码
     * @apiSuccess {String} user.id 房客id
     * @apiSuccess {String} user.token token
     * @apiSuccess {String} user.name 房客名称
     * @apiSuccess {String} user.mobile 手机号码
     * @apiSuccess {String} user.sex 性别 1男2女
     * @apiSuccess {String} user.birthday 出生日期
     * @apiSuccess {String} user.idCard 身份证号码
     * @apiSuccess {String} user.idCardFront 身份证正面
     * @apiSuccess {String} user.idCardReverse 身份证反面
     */
    @RequestMapping("/login")
    @Validator(name = {"code"}, format = {Format.NOT_NULL})
    public AjaxResult login(String code, String nickname) {
        return loginService.login(code, nickname);
    }

    /**
     * @api {post} /login/bindMobile 0.2.2绑定手机
     * @apiName login.bindMobile
     * @apiGroup login
     * @apiParam {String} token token
     * @apiParam {String} phone 手机号码
     * @apiParam {String} captcha 验证码
     */
    @AuthUser
    @Validator(name = {"phone", "captcha"}, format = {Format.REG_PHONE, Format.NOT_NULL})
    @RequestMapping("/bindMobile")
    public AjaxResult bindMobile(Tenant tenant, String phone, String captcha) {
        return loginService.bindMobile(tenant, phone, captcha);
    }


}
